/*河南星辰软件科技有限公司
@copyright Copyright (c) 2010~2022 All rights reserved.
*/
package cn.javaxc.oa.action.process;
import java.io.*;
import java.util.*;
import java.sql.*;
import cn.javaxc.model.base.SQL;
import cn.javaxc.model.base.SQLList;
import cn.javaxc.model.base.SQLMap;
import cn.javaxc.model.base.SQLParam;
import cn.javaxc.model.page.BatisPage;
import cn.javaxc.mvcwork.controller.web.TreeBean;
import cn.javaxc.mvcwork.util.common.CommonUtil;
import cn.javaxc.mvcwork.util.common.MapListUtil;
import cn.javaxc.mvcwork.util.helper.FrameHelper;
import cn.javaxc.mvcwork.util.helper.TreeTableHelper;
import org.springframework.beans.factory.annotation.Autowired;
import cn.javaxc.system.action.base.BaseAction;
import org.activiti.engine.RepositoryService;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.activiti.editor.constants.ModelDataJsonConstants;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.repository.Model;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.servlet.ModelAndView;
import cn.javaxc.oa.mapper.process.ModelMapper;
public class ModelAction extends BaseAction
{
    @Autowired(required=false)
	private ModelMapper mapper;
    
    @Autowired
    private RepositoryService repositoryService;
    @Autowired
    private ObjectMapper objectMapper;
    
    /**
    */
    
    public Object list() {
        
        Map result=new HashMap();
        SQLParam params=new SQLParam(request,result);
        
        SQLList<SQLMap> s_model=mapper.s_model(params);
        result.put("s_model", s_model);
        
        return s_model;
    }
    /**
    */
    
    public Map addModal() {
        
        Map result=new HashMap();
        SQLParam params=new SQLParam(request,result);
        return result;
    }
    /**
    */
    
    public Map deploy() {
        
        Map result=new HashMap();
        SQLParam params=new SQLParam(request,result);
        return result;
    }
    /**
    */
    
    public Map export_() {
        
        Map result=new HashMap();
        SQLParam params=new SQLParam(request,result);
        return result;
    }
    /**
    */
    
    public Object getModal() throws Exception {
        
        Map result=new HashMap();
        SQLParam params=new SQLParam(request,result);
        
        ObjectNode modelNode = null;
        Model model = repositoryService.getModel(getParameter("modelId"));
        if (model == null) {
            throw new ActivitiException("Error creating model JSON");
        }
        if (StringUtils.isNotEmpty(model.getMetaInfo())) {
            modelNode = (ObjectNode) objectMapper.readTree(model.getMetaInfo());
            } else {
            modelNode = objectMapper.createObjectNode();
            modelNode.put(ModelDataJsonConstants.MODEL_NAME, model.getName());
        }
        modelNode.put(ModelDataJsonConstants.MODEL_ID, model.getId());
        ObjectNode editorJsonNode = (ObjectNode) objectMapper.readTree(
        new String(repositoryService.getModelEditorSource(model.getId()), "utf-8"));
        
        
        result.put("model", editorJsonNode.toString());
        
        
        
        return result;
    }
    /**
    创建新模型修改
    */
    
    public Map modelModal() {
        
        Map result=new HashMap();
        SQLParam params=new SQLParam(request,result);
        return result;
    }
}